//
//  AXMySetVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/10/17.
//  Copyright © 2018年 tzhg. All rights reserved.
//

#import "AXMySetVC.h"
#import "UIViewController+HBD.h"
#import "AXMyActivitySpellVC.h"
#import "AboutAnxinViewController.h"
#import "AddressManagementViewController.h"
#import "AddressManagementViewController.h"
#import "ZXAccomplishFindPasswordVC.h"
#import "AXChangePasswordVC.h"
#import "AXLoginViewController.h"

@interface AXMySetVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic , strong) UIView *footerView;

@end

@implementation AXMySetVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self creatView];
    [self setlayout];
    self.view.backgroundColor = [UIColor whiteColor];
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    [self setupNavigationItems];
    
    /** tableview 的表尾按钮 */
    self.tableView.tableFooterView = _footerView;
    _footerView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = _footerView;
    
    
}

- (void)creatView {
    
    
    
    
    _footerView = [[UIView alloc]init];
    _footerView.userInteractionEnabled = YES;
    _footerView.backgroundColor = [UIColor redColor];
  
    
    UIButton *saveBtn = [[UIButton alloc]init];
    saveBtn.backgroundColor = COLOR_ORG;
    saveBtn.cornerRadius = 5;
    [saveBtn setTitle:@"退出" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(exitBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:saveBtn];
    
    
    saveBtn.sd_layout
    .leftSpaceToView(self.footerView, 50)
    .topSpaceToView(self.footerView, 50)
    .widthIs(SCREEN_WIDTH-100)
    .heightIs(44);
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    
}

- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hn)
    .widthIs(SCREEN_WIDTH)
    .heightIs(TableViewHeight);
    
    
}



- (void)setupNavigationItems {
    
    self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barShadowHidden = YES;
    
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"设置";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
}

- (void)backAction:(UIBarButtonItem *)item {
    
    [self.navigationController popViewControllerAnimated:YES];
}




#pragma mark - action

- (void)exitBtn:(UIButton *)btn {
    
    AXLoginViewController *vc = [[AXLoginViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
    
    
}

#pragma mark - tableview delegate & tableviewdatasource


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        AddressManagementViewController *vc = [[AddressManagementViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    else if (indexPath.row == 1) {
        
         AXChangePasswordVC *vc = [[AXChangePasswordVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
       
    }
    
    else if (indexPath.row == 2) {
     
        AboutAnxinViewController *vc = [[AboutAnxinViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }

 
    
}


//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)];
    view.backgroundColor = [UIColor whiteColor];
        UIImageView *img = [[UIImageView alloc]init];
        img.cornerRadius = 50;
        /** 图片比例切 */
        img.contentMode =UIViewContentModeScaleAspectFill;
        img.clipsToBounds=YES;//
        img.image = [UIImage imageNamed:@"xy.jpg"];
        [view addSubview:img];
        
        img.sd_layout
        .leftSpaceToView(view, 20)
        .centerYEqualToView(view)
        .widthIs(100)
        .heightIs(100);
        
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.text = @"哆啦A梦";
        nameLabel.textColor = COLOR_DIV;
        nameLabel.font = FONT_FOURTEEN;
        [view addSubview:nameLabel];
        
        nameLabel.sd_layout
        .leftSpaceToView(img, 10)
        .centerYEqualToView(img)
        .widthIs(100)
        .heightIs(30);
        
        UILabel *grade = [[UILabel alloc]init];
        grade.text = @"金牌会员";
        grade.textColor = COLOR_ORG;
        grade.font = FONT_FOURTEEN;
        [view addSubview:grade];
        
        grade.sd_layout
        .leftSpaceToView(img, 10)
        .topSpaceToView(nameLabel, 10)
        .widthIs(100)
        .heightIs(30);
        
        
        
        return view;

    
  
   
    
}
/** 分区的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 120;
}


//分区头
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    return view;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 100;
}





- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

// 返回每个分区中显示的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 4;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell != nil) {
        
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 200, 44)];
        label.textColor = COLOR_DIV;
        label.font = FONT_FOURTEEN;
        label.textAlignment = NSTextAlignmentLeft;
        [cell addSubview:label];
 
            
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 7, 200, 30)];
        titleLabel.text = @[@"我的收获地址",@"账户与安全",@"关于安心100",@"消息推送"][indexPath.row];
        titleLabel.textColor = COLOR_DIV;
        titleLabel.font = FONT_FOURTEEN;
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [cell addSubview:titleLabel];
        
            if (indexPath.row == 3) {
                
                UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-80, 0, 40, 44)];
                label.textColor = COLOR_DIV;
                label.font = FONT_FOURTEEN;
                label.text = @"关闭";
                label.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:label];
            
        }
        
    
    
        
    }
    
    
    
    return cell;
}



@end
